﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GaSaiGon.GUI
{
    public partial class frmQuanLyChuyenTau : Form
    {
        public frmQuanLyChuyenTau()
        {
            InitializeComponent();
        }

        private void frmQuanLyChuyenTau_Load(object sender, EventArgs e)
        {
            ChuyenTauBUS _ChuyenTauBUS = new ChuyenTauBUS();
            dgvDanhSachChuyenTau.DataSource = _ChuyenTauBUS.DanhSachChuyenTau();
            dgvDanhSachChuyenTau.AllowUserToAddRows = false;
        }

        private void btnThemCT_Click(object sender, EventArgs e)
        {
            frmThem_CapNhatChuyenTau _frmThemCT = new frmThem_CapNhatChuyenTau();
            _frmThemCT.Status = "Them";
            _frmThemCT.Show();
            _frmThemCT.FormClosed += new FormClosedEventHandler(_frmThemCT_FormClosed);
        }

        void _frmThemCT_FormClosed(object sender, FormClosedEventArgs e)
        {
            ChuyenTauBUS _ChuyenTauBUS = new ChuyenTauBUS();
            dgvDanhSachChuyenTau.DataSource = _ChuyenTauBUS.DanhSachChuyenTau();
        }

        private void btnCapNhatCT_Click(object sender, EventArgs e)
        {
            int IDChuyenTau = int.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["IDChuyenTau"].Value.ToString());
            frmThem_CapNhatChuyenTau _frmCapNhatCT = new frmThem_CapNhatChuyenTau();
            _frmCapNhatCT.Status = "CapNhat";
            _frmCapNhatCT.IDChuyenTau = IDChuyenTau;
            _frmCapNhatCT.Show();
            _frmCapNhatCT.FormClosed += new FormClosedEventHandler(_frmThemCT_FormClosed);
        }

        private void btnXoaCT_Click(object sender, EventArgs e)
        {
            int IDChuyenTau = int.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["IDChuyenTau"].Value.ToString());
            ChuyenTauDTO _ChuyenTauDto = new ChuyenTauDTO();
            _ChuyenTauDto.IDChuyenTau = IDChuyenTau;

            ChuyenTauBUS _ChuyenTauBus = new ChuyenTauBUS();
            _ChuyenTauBus.XoaChuyenTau(_ChuyenTauDto);

            dgvDanhSachChuyenTau.DataSource = _ChuyenTauBus.DanhSachChuyenTau();
        }

        private void btnXemChiTietCT_Click(object sender, EventArgs e)
        {
            frmChiTietChuyenTau _frmChiTiet = new frmChiTietChuyenTau();
            _frmChiTiet.IDChuyenTau = int.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["IDChuyenTau"].Value.ToString());
            _frmChiTiet.MaChuyenTau = dgvDanhSachChuyenTau.CurrentRow.Cells["MaChuyenTau"].Value.ToString();
            _frmChiTiet.LoaiChuyen = int.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["LoaiChuyen"].Value.ToString());
            _frmChiTiet.NgayKhoiHanh = DateTime.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["NgayKhoiHanh"].Value.ToString());
            _frmChiTiet.MaTau = dgvDanhSachChuyenTau.CurrentRow.Cells["MaTau"].Value.ToString();
            _frmChiTiet.ThongTinGa = int.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["ThongTinGa"].Value.ToString());
            _frmChiTiet.ThoiGian = int.Parse(dgvDanhSachChuyenTau.CurrentRow.Cells["ThoiGian"].Value.ToString());
            _frmChiTiet.Show();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            ChuyenTauBUS _ChuyenTauBus = new ChuyenTauBUS();
            ChuyenTauDTO _ChuyenTauDto = new ChuyenTauDTO();
            _ChuyenTauDto.MaChuyenTau = txtTimKiem.Text;
            dgvDanhSachChuyenTau.DataSource = _ChuyenTauBus.TimKiemChuyenTau(_ChuyenTauDto);
            dgvDanhSachChuyenTau.AllowUserToAddRows = false;
        }

    }
}
